package com.webtair.dump4j.objectdump;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class ObjectDumpStringList implements ObjectDump{
	List<String> strings = new LinkedList<String>();
	Iterator<String> savedIterator;
	public String getStringRepresentation() {
		return buildStringRepresentation();
	}

	private String buildStringRepresentation() {
		StringBuffer buffer = new StringBuffer();
		String endLine = "\n";
		for (Iterator iter = strings.iterator(); iter.hasNext();) {
			buffer.append((String)iter.next());
			if(iter.hasNext())
				buffer.append(endLine);
			else
				break;
		}
		return buffer.toString();
	}

	public String firstBlock() {
		savedIterator = null;
		return nextBlock();
	}

	public String nextBlock() {
		if(savedIterator == null)
			savedIterator = strings.iterator();
		if(savedIterator.hasNext())
			return savedIterator.next();
		return null;
	}

	public void addBlock(String block) {
		strings.add(block);
	}

	public void clear() {
		strings.clear();
	}

}
